/*
 * PayTransferInfoHolder.java
 * business
 *
 * Created by ChenTao on 2017/6/28.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.viewholder;

import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.response.QueryOrderResultResponse;
import com.yidiandao.business.ui.widget.listview.ViewHolder;
import com.yidiandao.business.utils.UIUtils;

import java.util.List;

/**
 * 订单支付成功银行转账信息
 * <p>
 * Created by ChenTao(chentao7v@gmail.com) on 2017-06-28 10:09
 */
public class PayTransferInfoHolder extends ViewHolder {
    private LinearLayout codeContainer;
    private TextView tvTransferHint;

    @Override
    protected void initView(View rootView) {
        codeContainer = (LinearLayout) rootView.findViewById(R.id.code_container);
        tvTransferHint = (TextView) rootView.findViewById(R.id.tv_transfer_hint);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_transfer_info;
    }

    public void refreshUI(QueryOrderResultResponse.Data data) {
        List<String> bankPayCodes = data.getBankPayCodes();
        String bankPayDesc = data.getBankPayDesc();
        tvTransferHint.setText(bankPayDesc);

        codeContainer.removeAllViews();

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        for (String code : bankPayCodes) {
            TextView textView = genTextView(code);
            textView.setLayoutParams(params);
            codeContainer.addView(textView);
        }
    }

    private TextView genTextView(String text) {
        TextView textView = new TextView(mContext);
        textView.setText(text);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, UIUtils.getDimens(R.dimen.dimen_16));
        textView.setTextColor(UIUtils.getColor(R.color.identify_code));
        textView.setIncludeFontPadding(false);
        return textView;
    }
}
